package com.cloudbroker.bcs.platform.ltb.common.constant.type;

import com.cloudbroker.bcs.common.constants.FileType;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * Created by xuyn15828 on 2016/3/24.
 */
public enum UploadType {
    IMG_JPG("img" , FileType.JPG.getSuffix()),
    IMG_PNG("img" , FileType.PNG.getSuffix()),
    IMG_BMP("img" , FileType.BMP.getSuffix()),
    IMG_GIF("img" , FileType.GIF.getSuffix()),
    AUDIO_MP3("audio" , FileType.MP3.getSuffix()),
    AUDIO_WAV("audio" , FileType.WAV.getSuffix()),
    IDCARD_JPG("idcard" , FileType.JPG.getSuffix()),
    IDCARD_PNG("idcard" , FileType.PNG.getSuffix()),
    IDCARD_BMP("idcard" , FileType.BMP.getSuffix());

    private String type;
    private String format;
    private static Map<String,Set<String>> acceptTypeAndFormat;

    UploadType(String type, String format) {
        this.format = format;
        this.type = type;
    }

    static {
        acceptTypeAndFormat = new HashMap<>();
        for(UploadType uploadType : UploadType.values()) {
            Set<String> formatSet = acceptTypeAndFormat.get(uploadType.type);
            if( null == formatSet )
                formatSet = new HashSet<>();
            formatSet.add(uploadType.format);
            acceptTypeAndFormat.put(uploadType.type , formatSet);
        }
    }

    public static boolean typeExists(String type) {
        return acceptTypeAndFormat.containsKey(type);
    }

    public static Set<String> collectType(String type) {
        return acceptTypeAndFormat.get(type);
    }
}
